<template>
	<view>

		<view v-for="(item, index) in list" :key="index">
			<u-cell :border="false" >
				<view slot="title">
					<text class="member_tag">{{item.name}}</text>
					
					<text style="margin-left: 10rpx;"> {{item.content}}</text>
					<text v-if="item.notice_nid" @click="goto_notice_detail(item.notice_nid,index)"  class="readmore">[查看]</text>
					
					<view class="data">
						<view class="date">{{item.add_time.slice(0,16)}}    </view>
					    <view v-if="item.read_status == '未读'" class="unread_status">{{list[index].read_status}}</view>
					    <view v-if="item.read_status == '已读'" class="read_status">{{list[index].read_status}}</view>
					</view>
					
					<text class="youqu-color" v-if="item.event_tag">【{{item.event_tag}}】</text>
					<!-- <text style="margin-left: 20rpx; font-size: 24rpx;color: #c8c9cc;">{{item.add_time.slice(0,16)}}</text> -->
				</view>
				<u-avatar @click="gotoMember(item.member_nid)" slot="icon" size="35" :src="item.headImg"
					customStyle="margin: 0 10px 0 0">
				</u-avatar>
			</u-cell>
			
			
			
			<view v-show="item.event_nid" class="detail" @click="gotoDetail(item)">
				<view class="left">
					<u--image :showLoading="true" :src="item.event_img" width="150px" height="50px"></u--image>
				</view>
				<view class="right">
					<u--text :text="item.event_name" :lines="2"></u--text>
				</view>

			</view>
			<u-divider></u-divider>
		</view>

		<u-empty v-if="this.list.length == 0" mode="message"></u-empty>
		
		<FollowOfficialAccount :show="officialShow"></FollowOfficialAccount>
	</view>
</template>

<script>
	import * as MemberApi from '@/api/member.js'
	import * as UserApi from '@/api/user.js'
	import * as MemberBrowseRecordApi from '@/api/member_browse_record.js'
	import FollowOfficialAccount from '@/components/common/FollowOfficialAccount.vue';
	export default {
		components: {
			FollowOfficialAccount
		},
		data() {
			return {
				page: 1,
				list: [],
				officialShow: false,
				circle_num:"0",
			}
		},
		onLoad() { 
			this.getList()
			this.getCircle_num()
		},
		onShow() {
			
	 
			MemberBrowseRecordApi.add({
				member_nid: uni.getStorageSync('user_id')
			}).then(res => {})
			
			
			
			
			// 移除徽标20240118 因为有局长通知，需要点击查看才消除统计的，所以不能直接去掉。
			// uni.removeTabBarBadge({
			//     index: 3
			// })
			
			UserApi.follow_official_account().then(res => {
				this.officialShow = res.info
			})
		},

		onReachBottom() {
			this.page++
			this.getList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			this.getList()
		},
		methods: {
			gotoMember(member_nid) {
				uni.navigateTo({
					url: '/pages/director/index?member_nid=' + member_nid
				});
			},
			
			getCircle_num() {
				MemberApi.circle_num().then(res => {
			
					// 设置徽标
					console.log(res)
					if (res.status == 200) {
						
						this.circle_num=res.data.circle_num
						
						if (res.data.circle_num > 0) {
							// 设置徽标
							uni.setTabBarBadge({
								index: 3, // 索引，从 0 开始，指定第几个 tabBar
								text: res.data.circle_num // 徽标中显示的文本
							})
							
						}
					}
				})
			},
			
			


		goto_notice_detail(nid,index) { 
			
			console.log("触发跳转和改变读数")
			
			    
				
				if(this.list[index].read_status=="未读")
				{
					
					
					let _circle_num=String(this.circle_num-1)
					console.log("触发改变读数",_circle_num)
					
							uni.setTabBarBadge({
								index: 3, // 索引，从 0 开始，指定第几个 tabBar
								text: _circle_num // 徽标中显示的文本
							})
							
                    this.circle_num=this.circle_num-1							
				}
				else
				{
					console.log("未触发读数")
					console.log("this.list[index].read_status",this.list[index].read_status)
					
				}
							
					this.list[index].read_status="已读"		
			
				uni.navigateTo({
					url: '/pages/activity/notice_detail?nid=' + nid + '&member_nid=' + uni.getStorageSync('user_id')
				});
			},

 

			gotoDetail(item) {

				if (item.is_cancel == 1) {
					uni.navigateTo({
						url: '/pages/myactivity/detail?id=' + item.event_nid
					})
				} else {
					uni.navigateTo({
						url: '/pages/activity/detail?id=' + item.event_nid
					})
				}

			},

			getList() {
				MemberApi.circle_list({
					member_nid: uni.getStorageSync('user_id'),
					page: this.page
				}).then(res => {

					this.list = this.list.concat(res.data)
					console.log("this.list",this.list)
					console.log("msg",res.msg)
					uni.stopPullDownRefresh()
				})
			} 
			
		}
	}
</script>



<style scoped lang="scss">
	@import url("asset/style.css");
</style>
 